package com.example.myapplication;

import androidx.appcompat.app.AppCompatActivity;

import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;
import android.widget.Toast;

import com.example.myapplication.databinding.ActivityMainBinding;

public class MainActivity extends AppCompatActivity {
    private final String TAG = "MainActivity";

    // Used to load the 'myapplication' library on application startup.
    static {
        System.loadLibrary("myapplication");
    }

    private ActivityMainBinding binding;
    private Button button_main;
    private Button button_caculator;


    private void find_layout_listen() {
        button_main = findViewById(R.id.button_main);
        button_main.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Toast.makeText(MainActivity.this, "Button被点击了", Toast.LENGTH_SHORT).show();
                Log.d(TAG, "class:" + getClass().getSimpleName() + ", func:" + new Throwable().getStackTrace()[0].getMethodName() + ", line:" + new Throwable().getStackTrace()[0].getLineNumber());
                Intent intent = new Intent(MainActivity.this, MyActivity1.class);
                startActivity(intent);
            }
        });
        button_caculator = findViewById(R.id.button_caculator);
        button_caculator.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Toast.makeText(MainActivity.this, "Caculator被点击了", Toast.LENGTH_SHORT).show();
                Log.d(TAG, "class:" + getClass().getSimpleName() + ", func:" + new Throwable().getStackTrace()[0].getMethodName() + ", line:" + new Throwable().getStackTrace()[0].getLineNumber());
                Intent intent = new Intent(MainActivity.this, CaculatorActivity.class);
                startActivity(intent);
            }
        });
    }


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        binding = ActivityMainBinding.inflate(getLayoutInflater());
        setContentView(binding.getRoot());

        // Example of a call to a native method
        TextView tv = binding.textMain;
        tv.setText(stringFromJNI());

        find_layout_listen();
    }

    /**
     * A native method that is implemented by the 'myapplication' native library,
     * which is packaged with this application.
     */
    public native String stringFromJNI();
}